using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Net;

namespace SpoonCore.Message.Info.Core
{
	public class ConfirmationInfo : AbstractMessageInfo
	{
		private static Random _rand = new Random();
		private int _id = _rand.Next();
		private ValidationStatus _status = ValidationStatus.Request;
		private int _timeout = 2;
		private int _ttl = 1;

		public ConfirmationInfo()
		{ }

		public ConfirmationInfo(int id, ValidationStatus status)
		{
			_id = id;
			_status = status;
		}

		public enum ValidationStatus : byte { Request, Response }

		public override int InfoId
		{
			get { return 1; }
		}

		public int Id
		{
			get { return _id; }
			set { _id = value; }
		}

		public ValidationStatus Status
		{
			get { return _status; }
			set { _status = value; }
		}

		public int Timeout
		{
			get { return _timeout; }
			set { _timeout = value; }
		}

		public int Ttl
		{
			get { return _ttl; }
			set { _ttl = value; }
		}

		public override byte[] GetBytes()
		{
			MemoryStream stream = new MemoryStream();
			BinaryWriter bw = new BinaryWriter(stream);

			bw.Write(_id);
			bw.Write((byte)Status);

			return stream.ToArray();
		}

		public override void SetBytes(BinaryReader br)
		{
			_id = br.ReadInt32();
			_status = (ValidationStatus)br.ReadByte();
		}

		public override AbstractMessageInfo Clone()
		{
			return new ConfirmationInfo();
		}

		/*public void Faild(IMessage message, ConfirmationInfo info, IPEndPoint destination)
		{
			if (OnConfirmationFaild != null) OnConfirmationFaild(message, info, destination);
		}*/
	}
}
